{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 43 统计分析"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.【选择】请选出合适的选项以补全如下代码：（ ）  \n",
    "import statsmodels.api as sm  \n",
    "#设置截距项这一超级参数  \n",
    "（ ）  \n",
    "X_add_const  \n",
    "Model = sm.OLS(y, X_add_const)  \n",
    "\n",
    "A.X_add_const=sm.add_constant(X)   \n",
    "B.X=sm.add_constant(X)  \n",
    "C.X_add_const=sm.add(X)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：A"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.【填空】（接上题）请在括号处填写合适的代码，以查看回归直线的“斜率”和“截距项”。  \n",
    "md=Model.fit()  \n",
    "（ ）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：md.params"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.【填空】（接上题）请写出评价回归直线拟合优度（R方）的命令。 （ ） "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：md.rsquared"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4.【填空】请在括号处填写合适的代码，以进行多项式回归分析。\n",
    "\n",
    "`import pandas as pd\n",
    "import numpy as np    \n",
    "df_women = pd.read_csv('women.csv', index_col=0)\n",
    "x = df_women[\"height\"]\n",
    "y = df_women[\"weight\"]\n",
    "（ ）\n",
    "x_add_const=sm.add_constant(x) \n",
    "x_add_const\n",
    "md_sec = sm.OLS(y, x_add_const)\n",
    "results_sec = md_sec.fit()\n",
    "print(results_sec.summary())`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：x=np.column_stack((x, np.power(x,2), np.power(x,3)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5.【编程】请对2017年全国各省市“居民消费水平”和“人均GDP”数据建立回归模型并进行分析。  \n",
    "数据来源URL：http://data.stats.gov.cn/easyquery.htm?cn=E0103 ，可自行下载所需要的数据"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：参见本章内容。"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
